<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <title>商家页面</title>
    <style>
        #div1 {
            position: absolute;
            top: 30%;
            left: 50%;
            transform: translate(-50%, -50%);
            text-align: center;
        }
        #div2{
            position: absolute;
            top: 40%;
            left: 50%;
            transform: translate(-50%, -50%);
            text-align: center;
        }
        table,tr,th,td{
            border: 1px solid #5fbdcb;
        }
        table{
            border-collapse: collapse;
        }
    </style>
</head>
<body>
<dl>
    <div id="div1">
        <button id="information">查看自己的信息</button><br>
    </div>
    <div id="div2">
        <a href="SellerStorePage.jsp">查看自己的店铺</a><br>
        <a href="SellerDoComplaint.jsp">投诉</a><br>
        <button id="button" >退出</button>
    </div>
</dl>
<script src="https://lib.sinaapp.com/js/jquery/2.0.2/jquery-2.0.2.min.js"></script>
<script>
    $(function () {
        $('#information').on("click",function () {
            $.ajax({
                url: "http://localhost:8080/user.do",
                type: "post",
                data: {
                    method: 'selectUser'
                },
                dataType: "text",
                success: function (data) {
                    let parse = JSON.parse(data);
                    let table = document.createElement('table');
                    let div1 = document.querySelector('#div1');
                    div1.appendChild(table);
                    let tr = document.createElement('tr');
                    table.appendChild(tr);
                    let th1 = document.createElement('th');
                    tr.appendChild(th1);
                    th1.innerText = '用户名';
                    let td1 = document.createElement('td');
                    tr.appendChild(td1);
                    td1.innerText = parse.userName;
                    let th2 = document.createElement('th');
                    tr.appendChild(th2);
                    th2.innerText = '邮箱';
                    let td2 = document.createElement('td');
                    tr.appendChild(td2);
                    td2.innerText = parse.email;
                    let button = document.querySelector('#information');
                    div1.removeChild(button);
                }
            })
        })
        $('#button').on('click',function (){
            $.ajax({
                url: "http://localhost:8080/user.do",
                type: "post",
                data: {
                    method: 'logout'
                },
                dataType: "text",
                success:function (data) {
                    if (data==='ok'){
                        window.location.href = '../Login.jsp';
                    }else {
                        alert("系统出错!");
                    }
                }
            })
        })
    })
</script>
</body>
</html>
